<table class="table table-hover">
  <thead>
    <tr>
      <th>#</th>
      <th>标题</th>
      <th>发布者</th>
      <th>发布日期</th>
      <th>操作</th>
    </tr>

  </thead>
  <tbody>
  <% if (results.length) { %>
  <% var id = 0 %>
  <% results.forEach(function(result){ %>
    <tr>
      <th scope="row"><%= id %></th>
      <td><%= result.get('title') %></td>
      <td class="author" id="<%= result.get('from').id %>">admin</td>
      <td><%= result.createdAt %></td>
      <td><a href="#" onclick=getContent("<%= result.id %>")>查看</a></td>
      <td><a href="#" onclick=del("/del?id=<%= result.id %>")>删除</a></td>
    </tr>
    <% id = id + 1 %>
    <% }) %>
  <% } %>

  </tbody>
</table>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalTitle">Modal title</h4>
      </div>
      <div class="modal-body" id="myModalBody">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary">保存</button>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
function del(url){
  if(confirm("确定要删除数据吗？")){
    window.location.href=url;
  }
}
function getContent(id){
  htmlobj=$.ajax({url:"/getContent?id=" + id,async:false});
  $("#myModalBody").text(htmlobj.responseText);
  htmlobj=$.ajax({url:"/getTitle?id=" + id,async:false});
  $("#myModalTitle").text(htmlobj.responseText);
  $('#myModal').modal('show')
}
function getAuthor(id){
  htmlobj=$.ajax({url:"/getUsername?id=" + id,async:false});
  return htmlobj.responseText;
}
</script>
<script type="text/javascript">
$(document).ready(function(){
  $(".author").each(function(){
    id = $(this).attr('id');
    $(this).text(getAuthor(id));
  });
});
</script>
